import { createRouter, createWebHashHistory } from 'vue-router';
import Layout from '@/layouts/index.vue';
import i18n from '@/locales';
const { global } = i18n;
export const constantRoutes = [
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/login/index.vue'),
    meta: {
      title: '登录',
    },
    hidden: true,
  },
];

export const asyncRoutes = [
  // {
  //   path: '/',
  //   component: Layout,
  //   redirect: '/index',
  //   name: 'Root',
  //   children: [
  //     {
  //       path: '/index',
  //       name: 'Index',
  //       component: () => import('../views/index/index.vue'),
  //       meta: {
  //         title: global.t('route.home'),
  //         icon: 'icon-home',
  //         affix: true,
  //         noKeepAlive: true,
  //       },
  //     },
  //   ],
  // },
  {
    path: '/more',
    component: Layout,
    redirect: '/more',
    name: 'more',
    children: [
      {
        path: '/more',
        name: 'more',
        component: () => import('../views/more/index.vue'),
        meta: {
          title: global.t('route.home'),
          icon: 'icon-home',
          affix: true,
          noKeepAlive: true,
        },
      },
    ],
  },
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    name: 'homeparent',
    children: [
      {
        path: '/home',
        name: 'home',
        component: () => import('../views/home/index.vue'),
        meta: {
          title: global.t('route.home'),
          icon: 'icon-home',
          affix: true,
          noKeepAlive: true,
        },
      },
    ],
  },
  {
    path: '/gameDetail',
    component: Layout,
    redirect: '/gameDetail',
    name: 'gameDetail',
    children: [
      {
        path: '/gameDetail',
        name: 'gameDetail',
        component: () => import('../views/gameDetail/index.vue'),
        meta: {
          title: global.t('route.home'),
          icon: 'icon-home',
          affix: true,
          noKeepAlive: true,
        },
      },
    ],
  },
  {
    path: '/mobileLogin',
    component: Layout,
    redirect: '/mobileLogin',
    name: 'mobileLogin',
    children: [
      {
        path: '/mobileLogin',
        name: 'mobileLogin',
        component: () => import('../views/mobileLogin/index.vue'),
        meta: {
          title: global.t('route.home'),
          icon: 'icon-home',
          affix: true,
          noKeepAlive: true,
        },
      },
    ],
  },
  {
    path: '/account',
    component: Layout,
    redirect: '/account',
    name: 'account',
    children: [
      {
        path: '/account',
        name: 'account',
        component: () => import('../views/account/index.vue'),
        meta: {
          title: global.t('route.home'),
          icon: 'icon-home',
          affix: true,
          noKeepAlive: true,
        },
      },
    ],
  },
  {
    path: '/chat',
    component: () => import('../views/chat/index.vue'),
    name: 'chat',
    meta: {
      title: global.t('route.home'),
      icon: 'icon-home',
      affix: true,
      noKeepAlive: true,
    },
  },
  {
    path: '/mobileRegister',
    component: () => import('../views/mobileRegister/index.vue'),
    name: 'mobileRegister',
    meta: {
      title: global.t('route.home'),
      icon: 'icon-home',
      affix: true,
      noKeepAlive: true,
    },
  },
  {
    path: '/recharge',
    component: () => import('../views/recharge/index.vue'),
    name: 'recharge',
    meta: {
      title: global.t('route.home'),
      icon: 'icon-home',
      affix: true,
      noKeepAlive: true,
    },
  },
  {
    path: '/withdrawal',
    component: () => import('../views/withdrawal/index.vue'),
    name: 'withdrawal',
    meta: {
      title: global.t('route.home'),
      icon: 'icon-home',
      affix: true,
      noKeepAlive: true,
    },
  },
  {
    path: '/wallet',
    component: Layout,
    redirect: '/wallet',
    name: 'wallet',
    children: [
      {
        path: '/wallet',
        name: 'wallet',
        component: () => import('../views/wallet/index.vue'),
        meta: {
          title: global.t('route.home'),
          icon: 'icon-home',
          affix: true,
          noKeepAlive: true,
        },
      },
    ],
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes: constantRoutes,
});

// reset router
export function resetRouter() {
  router.getRoutes().forEach((route) => {
    const { name } = route;
    if (name) {
      router.hasRoute(name) && router.removeRoute(name);
    }
  });
}

export default router;
